<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 


<html>
<head>
<base href="<%=basePath%>">
<title>人体图模拟</title>
<!-- Comon CSS -->
<link rel="stylesheet" type="text/css" href="<%=basePath%>/js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link href="./css/index.css" rel="stylesheet">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css" type="text/css"/>

<!-- MetisMenu CSS -->
<link href="./js/metisMenu/metisMenu.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="./css/sb-admin/sb-admin-2.css" rel="stylesheet">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css" type="text/css"/>
<link rel="icon" href="./images/icon/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./images/icon/favicon.ico" type="image/x-icon" />

<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.min.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="./js/common.js"></script>

<style>
body{font-size:14px !important;font-family:"microsoft yahei";}
.fixed-table-body{height:auto !important;}
</style>
</head>

<body>
	<jsp:include page="../template/head.jsp" />
	<jsp:include page="../template/leftnav.jsp" />
	<div id="page-wrapper">
		<div class="content">
			<ul id="myTab" class="nav nav-tabs">
				<li class="active" id="one"><a data-toggle="tab">男正面</a></li>
				<li id="two"><a data-toggle="tab">男背面</a></li>
				<li id="three"><a data-toggle="tab">女正面</a></li>
				<li id="four"><a data-toggle="tab">女背面</a></li>
				<li id="five"><a data-toggle="tab">男童正面</a></li>
				<li id="six"><a data-toggle="tab">男童背面</a></li>
				<li id="seven"><a data-toggle="tab">女童正面</a></li>
				<li id="eight"><a data-toggle="tab">女童背面</a></li>
			</ul>
			<div class="canvas_box" style="position:relative;">
				<img id="ck_img" src="images/man_1.png" >
				<canvas id="myCanvas" onclick="vControl('GETMOUSEPOSINPIC',this)" width="800"  height="800" style="position:absolute;top:0;left:0;">
				</canvas>
			</div>
		</div>
	</div>
	
	
	<div id="createwrap" style="display:none">
	  <form id="createwrapform" role="form" class="form-horizontal">
	    <div class="form-group">
	    	<label for="partName" class="col-sm-3 control-label">部位名称:</label>
	    	<div class="col-sm-8">
	      		<input class="form-control" id="partName" placeholder="请输入部位名称" onkeyup="filters(this)" onchange="filters(this)"/>
	    	</div>
	    	<br>
	    	<br>
	    </div>
	</div>
	
	<div id="editwrap" style="display:none">
	  <form id="editwrapform" role="form" class="form-horizontal">
	    <div class="form-group">
	    	<label for="partName1" class="col-sm-4 control-label">确认操作选择部位<span id="partName1"></span></label>
	    	<br>
	    </div>
	</div>
	
	<div id="showillnamewrap" style="display:none">
	  <form id="showillnamewrapform" role="form" class="form-horizontal">
	    <div class="form-group" id="showill">
	    	
	    </div>
	</div>
	
	<div id="showillanswerwrap" style="display:none">
	  <form id="showillanswerwrapform" role="form" class="form-horizontal">
	    <label for="illanswer" class="col-sm-7 control-label">查询结果：<span id="illanswer"></span>，是否还有其它症状</label>
    	<div class="col-sm-5">
      		<label>
	  		<input type="radio" name="inlineRadioOptions" id="yes" value="1" onkeyup="stripstript(this)"> 是
			</label>
			<label>
		  		<input type="radio" name="inlineRadioOptions" id="no" value="0" onkeyup="stripstript(this)"> 否
			</label>
    	</div>
    	<br>
	</div>
	
	<div id="showassistantexamswrap" style="display:none">
	  <form id="showassistantexamswrapform" role="form" class="form-horizontal">
	    <label >查询疾病需辅助检查确诊</label>
	    <br>
	    <div id="aexam">
	    </div>
    	<div style="margin-top:5px">
      		<label>
      		是否做辅助检查确诊:
	  		<input type="radio" name="inlineRadioOptions" id="yes" value="1" onkeyup="stripstript(this)"> 是
			</label>
			<label>
		  		<input type="radio" name="inlineRadioOptions" id="no" value="0" onkeyup="stripstript(this)"> 否
			</label>
    	</div>
    	<br>
	</div>
	
	<div id="showsymptomwrap" style="display:none">
	  <form id="showsymptomwrapform" role="form" class="form-horizontal">
	    <div class="form-group">
	    	<label for="symptom">相关病症:</label>
			<select id="symptoms">

			</select>
	    </div>
	</div>
	
	<div id="checkwrap" style="display:none">
	  <form id="checkwrapform" role="form" class="form-horizontal">
	    <div class="form-group">
	    	<label for="checksymptoms">您是否</label>
	    	<select id="checksymptoms">

			</select>
	    	<br>
	    </div>
	</div>
	
	<div id="selectAgewrap" style="display:none">
	  <form id="selectAgewrapform" role="form" class="form-horizontal">
	    <div class="form-group" id="age0">
	    	<label for="ages">年龄段</label>
	    	<select id="maleSel" multiple="multiple">
	    		<option value="0,6" selected>儿童(0~6)</option>
			    <option value="7,17" selected>少年(7~17)</option>
			    <option value="18,40" selected>青年(18~40)</option>
			    <option value="41,65" selected>中年(41~65)</option>
			    <option value="66,200" selected>老年(66~~)</option>
			</select>
	    	<br>
	    </div>
	</div>
	
	<div id="isInjuredwrap" style="display:none">
	  <form id="isInjuredwrapform" role="form" class="form-horizontal">
	  <label for="isInjured" class="col-sm-3 control-label">你是否受伤</label>
    	<div class="col-sm-5">
      		<label>
	  		<input type="radio" name="inlineRadioOptions" id="yes" value="1" onkeyup="stripstript(this)"> 是
			</label>
			<label>
		  		<input type="radio" name="inlineRadioOptions" id="no" value="0" onkeyup="stripstript(this)"> 否
			</label>
    	</div>
    	<br>
	</div>
	
</body>
<script type="text/javascript">
var sdiseaseAge;
var sexflag = $.getUrlParam("sexflag");
var prosAndCons = $.getUrlParam("prosAndCons");
if(!sexflag){
	sexflag = 'male';
}
if(!prosAndCons){
	prosAndCons = 'pros';
}
var usedSymptoms = [];
$(function(){
 	$("#myCanvas").attr('width',$("img#ck_img").width());
	$("#myCanvas").attr('height',$("img#ck_img").height());
	
	if(sexflag =="male" && prosAndCons=="pros"){
		$("#one").addClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/man_1.png";
	}else if(sexflag =="male" && prosAndCons=="cons"){
		$("#one").removeClass("active");
		$("#two").addClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/MMF.png";
	}else if(sexflag =="female" && prosAndCons=="pros"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").addClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/woman1.png";
	}else if(sexflag =="female" && prosAndCons=="cons"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").addClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/womanfan1.png";
	}else if(sexflag =="boy" && prosAndCons=="pros"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").addClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/child.png";
	}else if(sexflag =="boy" && prosAndCons=="cons"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").addClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/childfan.png";
	}else if(sexflag =="girl" && prosAndCons=="pros"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").addClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/girlz.png";
	}else if(sexflag =="girl" && prosAndCons=="cons"){
		$("#one").removeClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").addClass("active");
		document.getElementById("ck_img").src="images/girlfan.png";
	}else{
		$("#one").addClass("active");
		$("#two").removeClass("active");
		$("#three").removeClass("active");
		$("#four").removeClass("active");
		$("#five").removeClass("active");
		$("#six").removeClass("active");
		$("#seven").removeClass("active");
		$("#eight").removeClass("active");
		document.getElementById("ck_img").src="images/man_1.png";
	} 

 	$.ajax({
       url: "./partInteraction/getAllCoordinate.spring",
       data: {
           sexflag : sexflag,
           prosAndCons :prosAndCons
       },
       type: "POST",
       dataType: 'json',
       cache: false,
       success: function (ret) {
           if (ret!=null) {
               for(var i=0;i<ret.length;i++){
			 		drawPoint(ret[i].coordinate_X,ret[i].coordinate_Y,ret[i].parts);
			 	}
           }
       }
   });
	var activeTab;
	$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
		activeTab = $(e.target).text();
		if(activeTab=="男正面"){
			sexflag = 'male';
			prosAndCons = 'pros';
		}else if(activeTab=="男背面"){
			sexflag = 'male';
			prosAndCons = 'cons';
		}else if(activeTab=="女正面"){
			sexflag = 'female';
			prosAndCons = 'pros';
		}else if(activeTab=="女背面"){
			sexflag = 'female';
			prosAndCons = 'cons';
		}else if(activeTab=="男童正面"){
			sexflag = 'boy';
			prosAndCons = 'pros';
		}else if(activeTab=="男童背面"){
			sexflag = 'boy';
			prosAndCons = 'cons';
		}else if(activeTab=="女童正面"){
			sexflag = 'girl';
			prosAndCons = 'pros';
		}else if(activeTab=="女童背面"){
			sexflag = 'girl';
			prosAndCons = 'cons';
		}else{
			sexflag = 'male';
			prosAndCons = 'pros';
		}
		location.href = "./jsp/illness/bodysimulation.jsp?sexflag="+sexflag+"&prosAndCons="+prosAndCons;
	});
	
	/* selectAge(); */
	
	$('#maleSel').multiselect({
	 	includeSelectAllOption: true,
	 	selectAllText: "全部年龄",
	 	allSelectedText:"全选",
	 	nonSelectedText:"无",
	 	buttonWidth: '150px'
	 });
	 
});


function selectAge(){
	$("#selectAgewrap").show();
	var age = $("#maleSel").val();
	if(age.length>0){
		var l = age.length;
		if(l==1){
			sdiseaseAge = age[0];
		}else{
			sdiseaseAge=(age[0].split(","))[0]+","+(age[l-1].split(","))[1];
		}
	}else{
		sdiseaseAge = '';
	}
	$("#selectAgewrap").dialog({
         	title   : "请选择年龄段:",
        	'class' :  "mydialog",
        	onClose : function() {
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		$(this).dialog("close");
             	}
             },{
             text : "退出",
             'class' : "btn btn-default",
             click : function() {
                	$(this).dialog("close");
             	}
         }]
     });
}

function drawPoint(x,y,part){
	var c=document.getElementById("myCanvas");
	var cxt=c.getContext("2d");
	cxt.fillStyle="#5bc0de";
	cxt.beginPath();
	cxt.arc(x,y,0,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
/* 	var c=document.getElementById("myCanvas");
	var cxt=c.getContext("2d");
	cxt.fillStyle="#ffffff";
	cxt.beginPath();
	cxt.arc(x,y,0,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill(); */
	showPoint(x,y,part);
}

var JPos = {};  
(function($){  
    $.$getAbsPos = function(p){  
        var _x = 0;  
        var _y = 0;  
        while(p.offsetParent){  
                _x += p.offsetLeft;  
                _y += p.offsetTop;  
                p = p.offsetParent;  
        }  
          
        _x += p.offsetLeft;  
        _y += p.offsetTop;  
          
        return {x:_x,y:_y};  
    };  
      
    $.$getMousePos = function(evt){  
        var _x,_y;  
        evt = evt || window.event;  
        if(evt.pageX || evt.pageY){  
            _x = evt.pageX;  
            _y = evt.pageY;  
        }else if(evt.clientX || evt.clientY){  
            _x = evt.clientX + document.body.scrollLeft - document.body.clientLeft;  
            _y = evt.clientY + document.body.scrollTop - document.body.clientTop;  
        }else{  
            return $.$getAbsPos(evt.target);      
        }  
        return {x:_x,y:_y};  
    }  
})(JPos);  
  
function vControl(pChoice){  
    switch(pChoice){  
        case "GETMOUSEPOSINPIC":  
            var mPos = JPos.$getMousePos();  
            var iPos = JPos.$getAbsPos(arguments[1]);  
            var x = mPos.x - iPos.x;  
            var y = mPos.y - iPos.y; 
            window.status = (mPos.x - iPos.x) + " " + (mPos.y - iPos.y);
            editBlank(x,y);
            break;  
    }  
}  

function showTooltip(x,y,color,contents) {
	$('<div id="tooltip">' + contents + '<div>').css({
		position: 'absolute',
		display: 'none',
		top: y-30,
		left: x-35,
		border: '1px solid ' + color,
		padding: '5px',
		'font-size': '10px',
		'border-radius': '5px',
		'background': '#fff',
		'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
	    opacity: 0.9
	}).appendTo(".canvas_box").fadeIn(200);
	
}

function showPoint(x,y,part) {
	$('<div id="point'+x*y*800+'"><div>').css({
		position: 'absolute',
		display: 'none',
		top: y-5,
		left: x-5,
		border: '1px solid ' + '#9bc0de',
		padding: '5px',
		'border-radius': '5px',
		'background': '#fff',
		'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
	    opacity: 0.5
	}).appendTo(".canvas_box").fadeIn(200);
	
	$('#point'+x*y*800+'').on('mouseover',function(){
	    $('#point'+x*y*800+'').css("background-color","blue");
	    showTooltip(x,y,"#5bc0de",part);
	});
	
	$('#point'+x*y*800+'').on('mouseout',function(){
	    $('#point'+x*y*800+'').css("background-color","white");
	    var my = document.getElementById("tooltip");
	    if (my != null){
        	my.parentNode.removeChild(my);
        }
	});
	
	$('#point'+x*y*800+'').click(function(){
		var my = document.getElementById("tooltip");
	    if (my != null){
        	my.parentNode.removeChild(my);
        }
	    editPoint(x,y,part);
	});
}

//编辑空白
function editBlank(x,y){
	$.messager.model = { 
	   	ok:{ text: "确定", classed: 'btn-success' },
	    cancel:{text:"取消",classed: 'btn-danger' }
	};
	$.messager.confirm("确认操作", "确定新增部位?", function() {
		createCoordinate(x,y);
	});
}

//创建人体图坐标
function createCoordinate(x,y){
	$("#createwrap").show();
	$("#createwrap").dialog({
         	title   : "新增部位",
        	'class' :  "mydialog",
        	onClose : function() { 
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "提交",
          		'class' : "btn btn-primary",
             	click : function() {
             		var part = $("#partName").val();
             		
                    $.ajax({
                     url: "./partInteraction/saveCoordinate.spring",
                     data: {
                         part: part,
                         sexflag: sexflag,
                         prosAndCons: prosAndCons,
                         coordinate_X : x,
                         coordinate_Y : y
                     },
                     type: "POST",
                     dataType: 'json',
                     cache: false,
                     success: function (ret) {
                         if(ret.resultCode==0){
                         	location.reload();
                         }
                     }
                 });
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
                	 $(this).dialog("close");
             	}
         }]
     });
}

//编辑点
function editPoint(x,y,partName){
	$("#editwrap").show();
	$("#partName1").text(" '"+partName+"'");
	$("#editwrap").dialog({
         	title   : "确认操作:",
        	'class' :  "mydialog",
        	onClose : function() {
         		$(this).dialog("close");
          	}, 
          	buttons : [/* {
          		text : "确定",
          		'class' : "btn btn-primary",
             	click : function() {
             		showIsInjured(partName);
             		$(this).dialog("close");
             	}
             }, */{
             text : "删除",
             'class' : "btn btn-info",
             click : function() {
             		deletePoint(x,y,partName);
                	$(this).dialog("close");
             	}
         },
         {
             text : "取消",
             'class' : "btn btn-default",
             click : function() {
                	$(this).dialog("close");
             	}
         }]
     });
}

function deletePoint(x,y,partName){
	$.ajax({
        url: "./partInteraction/deletePoint.spring",
        data: {
            coordinate_X : x,
            coordinate_Y : y,
            sexflag : sexflag,
            prosAndCons : prosAndCons
        },
        type: "POST",
        dataType: 'json',
        cache: false,
        success: function (ret) {
            if(ret.resultCode==0){
            	$.messager.popup("部位："+partName+",删除成功！");
            	location.reload()
            }else{
            	$.messager.popup("部位："+partName+",删除失败！");
            }
        }
    });
}

function showIsInjured(partName){
	$("#isInjuredwrap").show();
	$("#isInjuredwrap").dialog({
         	title   : "受伤情况:",
        	'class' :  "mydialog",
        	onClose : function() {
        		$('input[name="inlineRadioOptions"]:checked').attr("checked",false); 
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		if($('input[name="inlineRadioOptions"]:checked').val()){
	             		getIllByparts(partName,$('input[name="inlineRadioOptions"]:checked').val());
	             		$(this).dialog("close");
             		}else{
             			$.messager.popup("请选择“是”或“否”");
             		}
             	}
             },{
             text : "退出",
             'class' : "btn btn-default",
             click : function() {
             		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);	
                	$(this).dialog("close");
             	}
         }]
     });
}

//1，按部位查出该部位的所有疾病名称
function getIllByparts(partName,isInjured){
	$.ajax({
         /* url: "./illOper/getIllByparts.spring", */
         url: "./illOper/getIllnessInParts.spring",
         data: {
             parts: partName,
             sex:sexflag,
             isInjured:isInjured,
             diseaseAge : sdiseaseAge
         },
         type: "POST",
         dataType: 'json',
         cache: false,
         success: function (ret) {
             if(ret!=null){
             	if(ret.ids.length>0){
             		showill(ret,partName);
             	}else{
             		$.messager.popup("该部位还未录入疾病，请联系您主治医生，给您带来不便请谅解！");
             	}
             }
         }
     });
}

//显示部位所有的相关疾病
function showill(ret,partName){
	$("#showillnamewrap").show();
	createNode("showill",ret.ills);
	$("#showillnamewrap").dialog({
         	title   : partName+"相关疾病:",
        	'class' :  "mydialog",
        	onClose : function() {
        		deleteNode("showill"); 
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		$(this).dialog("close");
                    getSymptomsByillList(ret.ids);
                    deleteNode("showill");
             	}
             },{
             text : "退出",
             'class' : "btn btn-default",
             click : function() {
             		deleteNode("showill");	
                	$(this).dialog("close");
             	}
         }]
     });
}

//添加所有子节点
function createNode(name,args){
	var div = document.getElementById(name);
	for(var i=0;i<args.length;i++){
		var textNode = document.createTextNode(args[i]+" ");
		div.appendChild(textNode);
	}
}

//删除所有子节点
function deleteNode(name){
	var div = document.getElementById(name);
    while(div.hasChildNodes()) //当div下还存在子节点时 循环继续
    {
        div.removeChild(div.firstChild);
    }
}

//按疾病id获取所有这些id的病症
function getSymptomsByillList(ids){
	$.ajax({
         url: "./illOper/getSymptomsByillList.spring",
         data: {
             ids: ids.join(",")
         },
         type: "POST",
         dataType: 'json',
         cache: false,
         success: function (ret) {
             if(ret!=null){
             	usedSymptoms = [];
             	showSymptoms(ret.symptoms,ret.ids,usedSymptoms);
             	//checkill(ret.symptom,ret.ids);
             }
         }
     });
}

//显示所有的病症，可以单选
function showSymptoms(symptoms,ids,usedSymptoms){
	$("#showsymptomwrap").show();
	var mySelect = document.getElementById("symptoms");
	for(var i=0;i<symptoms.length;i++){
		var opp = new Option(symptoms[i],symptoms[i]);
		mySelect.add(opp);
	}
	$("#showsymptomwrap").dialog({
         	title   : "请选择一项相关病症:",
        	'class' :  "mydialog",
        	onClose : function() {
        		while(mySelect.firstChild) {
				    mySelect.removeChild(mySelect.firstChild);
				}
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		usedSymptoms.push($("#symptoms").val());
                    $.ajax({
                     url: "./illOper/getIllByIdAndsymptomsYes.spring",
                     data: {
                         symptom: $("#symptoms").val(),
                         symptoms : usedSymptoms.join(","),
                         ids : ids
                     },
                     type: "POST",
                     dataType: 'json',
                     cache: false,
                     success: function (ret) {
                         if(ret!=null){
                         	if(ret.ids.length==0){
                         		$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
                         	}else if(ret.ids.length==1){//当id只有一个的时候直接跳到疾病的诊疗方案
                         		getIllByid(ret.ids[0]);
                         	}else{//进入问题列表，匹配对应的疾病
                         		if(ret.syms!=null){
	                         		illQuestion(ret.syms,ret.ids);
	                         	}
                         	}
                         }
                     }
                 });
                 while(mySelect.firstChild) {
				    mySelect.removeChild(mySelect.firstChild);
				}
				$(this).dialog("close");
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
             		while(mySelect.firstChild) {
					    mySelect.removeChild(mySelect.firstChild);
					} 
                	$(this).dialog("close");
             	}
         }]
     });
}

//当id只有一个的时候，按id获取疾病
function getIllByid(id){
	$.ajax({
        url: "./illOper/getIll2ById.spring",
        data: {
            id : id
        },
        type: "POST",
        dataType: 'json',
        cache: false,
        success: function (ret) {
            if(ret!=null){
            	if(ret.assistantExams.length>0){
            		showAssistantExams(ret.assistantExams,ret.illness);
            	}else{
            		illAnswer(ret.illness);
            	}
            }else{
            	$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
            }
        }
    });
}

function showAssistantExams(assistantExams,illness){
	$("#showassistantexamswrap").show();
	var div = document.getElementById("aexam");
	for(var i=0;i<assistantExams.length;i++){
		var textNode = document.createTextNode(assistantExams[i]+" ");
		div.appendChild(textNode);
	}
	$("#showassistantexamswrap").dialog({
         	title   : "查询结果",
        	'class' :  "mydialog",
        	onClose : function() { 
        		deleteNode("aexam");
        		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		if($('input[name="inlineRadioOptions"]:checked').val()){
	             		//当选择“是”时，提示不存在这种疾病
	             		if($('input[name="inlineRadioOptions"]:checked').val()==1){
	             			 $.messager.popup("您查询的疾病已发起辅助检查请求，请联系您主治医生，以方便安排您做辅助检查，进一步确诊您的疾病！");
	             		}else if($('input[name="inlineRadioOptions"]:checked').val()==0){
	             			if(illness){
	             				illAnswer(illness);
	             			}else{
	             				$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
	             			}
	             		}
	             		deleteNode("aexam");
	             		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
	             		$(this).dialog("close");
             		}else{
             			$.messager.popup("请选择“是”或“否”");
             		}
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
             		deleteNode("aexam");
             		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
                	$(this).dialog("close");
             	}
         }]
     });

}

//疾病匹配结果
function illAnswer(illname){
	$("#showillanswerwrap").show();
	$("#illanswer").text(illname);
	$("#showillanswerwrap").dialog({
         	title   : "查询结果",
        	'class' :  "mydialog",
        	onClose : function() { 
        		$("#illanswer").text('');
        		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		console.log($('input[name="inlineRadioOptions"]:checked').val());
             		if($('input[name="inlineRadioOptions"]:checked').val()){
	             		//当选择“是”时，提示不存在这种疾病
	             		if($('input[name="inlineRadioOptions"]:checked').val()==1){
	             			 $.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
	             		}else if($('input[name="inlineRadioOptions"]:checked').val()==0){
	             			//当选择“否”时，跳转到该疾病的诊断方案(疾病详情页)
	             			window.location = "./jsp/illness/illnessdetail.jsp?illName="+illname;
	             		}
	             		$("#illanswer").text('');
	             		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
	             		$(this).dialog("close");
             		}else{
             			$.messager.popup("请选择“是”或“否”");
             		}
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
             		$("#illanswer").text('');
             		$('input[name="inlineRadioOptions"]:checked').attr("checked",false);
                	$(this).dialog("close");
             	}
         }]
     });
}

//疾病问题
function illQuestion(syms,ids){
	$("#checkwrap").show();
	var mySelect = document.getElementById("checksymptoms");
	for(var i=0;i<syms.length;i++){
		var opp = new Option(syms[i],syms[i]);
		mySelect.add(opp);
	}
	$("#checkwrap").dialog({
         	title   : "问题",
        	'class' :  "mydialog",
        	onClose : function() { 
        		while(mySelect.firstChild) {
				    mySelect.removeChild(mySelect.firstChild);
				}
         		$(this).dialog("close");
          	}, 
          	buttons : [{
          		text : "下一步",
          		'class' : "btn btn-primary",
             	click : function() {
             		//把选择的症状加入usedSymptoms数组存起来
             		usedSymptoms.push($("#checksymptoms").val());
           			 $.ajax({
	                     url: "./illOper/getIllByIdAndsymptomsYes.spring",
	                     data: {
	                         symptom: $("#checksymptoms").val(),
	                         symptoms : usedSymptoms.join(","),
	                         ids : ids.join(",")
	                     },
	                     type: "POST",
	                     dataType: 'json',
	                     cache: false,
	                     success: function (ret) {
	                     	while(mySelect.firstChild) {
							    mySelect.removeChild(mySelect.firstChild);
							}
	                         if(ret!=null){
	                         	if(ret.ids.length==0){ //疾病的id是空，即没有疾病
	                         		$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
	                         	}else if(ret.ids.length==1){ //疾病只有一个
	                         		$("#checkwrap").dialog("close");
	                         		getIllByid(ret.ids[0]);
	                         	}else if(ret.ids.length>1 && ret.syms.length>=1){ //疾病有多个，病症还有多个，继续问题
	                         		$("#checkwrap").dialog("close");
	                         		illQuestion(ret.syms,ret.ids);
	                         	}else if(ret.ids.length>1 && ret.syms.length==0){ //疾病有多个，病症为空，跳出，进行查找有没辅助检查
	                         		getillsByIds(ret.ids);
	                         	}else{											//其它清空提示和退出
	                         		$("#checkwrap").dialog("close");
	                         		$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
	                         	}
	                         }
	                     }
	                 });
             	}
             },{
             text : "关闭",
             'class' : "btn btn-default",
             click : function() {
             		while(mySelect.firstChild) {
							    mySelect.removeChild(mySelect.firstChild);
							}
                	 $(this).dialog("close");
             	}
         }]
     });
}

//当疾病id为多个，但是病症为空时,根据疾病id查询是否还有辅助检查
function getillsByIds(ids){
	$.ajax({
        url: "./illOper/getExamByillList.spring",
        data: {
            ids : ids.join(",")
        },
        type: "POST",
        dataType: 'json',
        cache: false,
        success: function (ret) {
            if(ret!=null){
            	if(ret.length>0){
            		showAssistantExams(ret);
            	}else{
            		$.messager.popup("您查询的疾病无法分辨，请联系您主治医生，给您带来不便请谅解！");
            	}
            }else{
            	$.messager.popup("您查询的疾病不存在，请联系您主治医生，给您带来不便请谅解！");
            }
        }
    });
}

//删除数组的第一个元素
function delectFirstElement(arr){
	var reArr = [];
	for(var i=0;i<arr.length-1;i++){
		reArr.push(arr[i+1]);
	}
	return reArr;
}

</script>
</html>
	